{extends file="../acp.html"}

{block name="title"}{$head_title}{/block}
{block name="content"}
<div class="t-a-wait-con">
    <div class="tablesWrap"> 
    	<div class="tables-searchbox">
            <div class="t-a-wait-top">
                <form action="" method="post" id="rank_waiting">
                <div class="t-a-wait-top-li"><span>姓名：</span><input type="text" placeholder="" value="{$realname}" class="mini" name="realname"> </div>
                <div class="t-a-wait-top-li"><span>手机号：</span><input type="text" placeholder="" value="{$mobile}" class="mini" name="mobile"> </div>

                <div class="t-a-wait-top-li" style=""><input type="hidden" name="submit" value="search" /><button class="btn"><i class="gicon-search"></i>搜索</button> </div>
              </form>
            </div>        
        </div> 
        <table class="wxtables">  
            <colgroup>  
            <col width="5%"> 
            <col width="10%">  
            <col width="10%">  
            <col width="10%">  
            <col width="7%"> 
            <col width="10%">  
            <col width="10%"> 
            <col width="10%"> 
            <col width="13%">
            </colgroup>  
            <thead>  
                <tr>  
                    <td>选择</td>   
                    <td>姓名</td>
                    <td>职位</td>  
                    <td>手机</td>
                    <td>城市</td>
                    <td>所在机构</td>
                    <td>关注领域</td>
                    <td>关注阶段</td>
                    <td>操作</td>  
                </tr>  
            </thead>  
            <tbody>
				{foreach from=$user_list item=user}
                <tr>  
                    <td><input type="checkbox" class="checkbox" value='{$user.user_id}' name="a[]"></td> 
                    <td>{$user.realname}</td>  
                    <td>{$user.position}</td>  
                    <td>{$user.mobile}</td>
                    <td>{$user.city}</td>
                    <td>{$user.company_address}</td>
                    <td>
					{foreach from=$user.follow_field item=field}
                    {$field}&nbsp;&nbsp;&nbsp;
					{/foreach}
                    </td>
                    <td>
					{foreach from=$user.follow_phase item=phase}
                    {$phase}&nbsp;&nbsp;&nbsp;
					{/foreach}
                    </td>
                    <td>
                        <a href="/AcpUser/auth_user_detail/user_id/{$user.user_id}" class="btn" title="查看用户详情">详情</a>  
                        {if $opt == 'wait_auth'}
                        <a href="javascript:void(0)" onclick='pass({$user.user_id})' class="btn" title="通过认证">通过认证</a> 
                        <a href="javascript:void(0)" onclick='refuse({$user.user_id})' class="btn" title="拒绝通过">拒绝通过</a>  
                        {/if}
                    </td>  
                </tr>
                {foreachelse}
					<tr><td colspan="11">没有符合条件的用户</td></tr>
                {/foreach}
            </tbody>  
        </table>  
        <!-- end wxtables -->  
        <div class="tables-btmctrl clearfix">  
            <div class="fl">  
				<a href="javascript:;" class="btn btn-blue" onclick="Select()">全选</a>  
				<a href="javascript:;" class="btn btn-blue" onclick="Cancel()">取消</a>  
                <!-- <a href="javascript:void(0);" class="btn btn-blue" onclick="batch_set_is_enable(2)">批量禁用</a> 
                 <a href="javascript:void(0);" class="btn btn-blue" onclick="batch_set_is_enable(1)">批量激活</a> --> 
                {if $opt == 'user'}<!--  <a href="javascript:void(0);" class="btn btn-blue" onclick="batch_send_freight_coupon()">批量发放优惠券</a> --> {/if}
            </div>
            <div class="fr">  
                <div class="paginate">  
                    {$show}
                </div>  
                <!-- end paginate -->  
            </div>  
        </div>  
        <!-- end tables-btmctrl -->  
    </div>  
    <!-- end tablesWrap --> 
</div>
{/block} 

{block name="js"}
<script src="/Public/Plugins/My97DatePicker/WdatePicker.js?version={$version}"></script>
<script>
    var url = '{$url}';
//全选
function Select(){
	var sel=document.getElementsByName("a[]");
	for(var i=0;i<sel.length;i++){
		sel[i].checked=true;
	}
}
//取消全选
function Cancel(){
	var sel=document.getElementsByName("a[]");
	for(var i=0;i<sel.length;i++){
		sel[i].checked=false;
	}
}

{literal} 
function pass(user_id)
{
	$.jPops.confirm(
	{  
		 title:"提示",  
		 content:"您确定要执行该操作吗？",  
		 okBtnTxt:"确定",  
		 cancelBtnTxt:"取消",  
		 callback:function(r)
		 {  
			 if(r)
			 {
				 $.post('/AcpUser/set_auth_status', {"user_id":user_id, "status":1}, function(data, textStatus) 
				 {
					if (data == 'success')
					{
						alert('恭喜您，认证通过成功！');
						location.reload();
					}
					else
					{
						alert('对不起，认证通过失败');
					}
				});
			 }  
			 return true;  
		 }
	 });  	
}


function refuse(user_id)
{
	var html='';

	var html='<form id="deliver_form">' + 
			'<div class="formitems inline">'+
				'<label class="fi-name"><span class="colorRed">*</span>未通过原因：</label>'+ 
				'<div class="form-controls">'+
					'<textarea name="reason" id="reason"></textarea><span class="fi-help-text"> </span>'+
				'</div>' + 
			'</div>'+
		'</form>';
	
	$.jPops.custom({
		title:"认证拒绝",  
		content:html,
		okBtnTxt:"确定",  
		cancelBtnTxt:"取消",  
		callback:function(r)
		{
			if(r)
			{
			    var reason  = $('#reason').val();

				$.validator.setDefaults(
				{
					//表单验证通过后的处理，异步提交表单
					submitHandler: function()
					{
						$.post('/AcpUser/set_auth_status',{"user_id":user_id,'status':2, "reason":reason},function(data)
						{
							if (data == 'success')
							{
								alert('恭喜您，操作成功');
								location.reload();
							}
							else
							{
								alert('对不起，操作失败');
							}
						})
						acp.batchDeliverFormStatus = true;
					}
				});
			
				//表单验证规则
				$("#deliver_form").validate(
				{
					rules: 
					{
						reason: 
						{
							required: true,
						},
					},
					messages: 
					{
						freight_num: 
						{
							required: "对不起，请填写未通过原因",
						},
					},
					errorPlacement: acp.form_ShowError,//显示出错信息(这段代码必须加)
					success:acp.form_HideError//验证成功隐藏错误信息(这段代码必须加)
				});

				//模拟提交表单
				$("#deliver_form").submit();
				return acp.batchDeliverFormStatus;
			}
			else
			{
				return true;  
			}
		}
	});
}

function send_freight_coupon(user_id)
{
	var html='';

	var html='<form id="deliver_form">' + 
			'<div class="formitems inline">'+
				'<label class="fi-name"><span class="colorRed">*</span>优惠券名称：</label>'+ 
				'<div class="form-controls">'+
					'<input name="freight_name" id="freight_name"><span class="fi-help-text"> </span>'+
				'</div>' + 
			'</div>'+
			'<div class="formitems inline">'+
            '<label class="fi-name"><span class="colorRed">*</span>优惠券使用条件( > 元)：</label>'+ 
				'<div class="form-controls">'+
					'<input name="price_limit" id="price_limit"><span class="fi-help-text"> </span>'+
				'</div>' + 
			'</div>'+
			'<div class="formitems inline">'+
				'<label class="fi-name"><span class="colorRed">*</span>优惠券面额：</label>'+ 
				'<div class="form-controls">'+
					'<input name="freight_num" id="freight_num"><span class="fi-help-text"> </span>'+
				'</div>' + 
			'</div>'+
			'<div class="formitems inline">'+
				'<label class="fi-name"><span class="colorRed">*</span>有效天数：</label>'+ 
				'<div class="form-controls">'+
					'<input name="valid_day_num" id="valid_day_num"><span class="fi-help-text"> </span>'+
				'</div>' + 
			'</div>'+
		'</form>';
	
	$.jPops.custom({
		title:"发放优惠券",  
		content:html,
		okBtnTxt:"确定",  
		cancelBtnTxt:"取消",  
		callback:function(r)
		{
			if(r)
			{
			    var freight_name  = $('#freight_name').val();
				var freight_num   = $('#freight_num').val();
				var valid_day_num = $('#valid_day_num').val();
				var price_limit   = $('#price_limit').val();

				$.validator.setDefaults(
				{
					//表单验证通过后的处理，异步提交表单
					submitHandler: function()
					{
						$.post('/AcpPromo/dispatch_coupon',{"user_id":user_id,"num":freight_num,"valid_day_num":valid_day_num, "coupon_name":freight_name, "price_limit":price_limit},function(data)
						{
							if (data == 'success')
							{
								alert('恭喜您，操作成功');
							}
							else
							{
								alert('对不起，操作失败');
							}
						})
						acp.batchDeliverFormStatus = true;
					}
				});
			
				//表单验证规则
				$("#deliver_form").validate(
				{
					rules: 
					{
						freight_num: 
						{
							required: true,
							digits: true
						},
						valid_day_num: 
						{
							required: true,
							digits: true
						},
					},
					messages: 
					{
						freight_num: 
						{
							required: "对不起，请填写面额",
							digits: "面额请填写数字!"
						},
						valid_day_num: 
						{
							required: "对不起，请填写有效天数",
							digits: "有效天数请填写数字!"
						},
					},
					errorPlacement: acp.form_ShowError,//显示出错信息(这段代码必须加)
					success:acp.form_HideError//验证成功隐藏错误信息(这段代码必须加)
				});

				//模拟提交表单
				$("#deliver_form").submit();
				return acp.batchDeliverFormStatus;
			}
			else
			{
				return true;  
			}
		}
	});
}

</script>
{/literal} 
{/block} 

{block name="css"}
<link rel="stylesheet" href="/Public/Css/acp/AcpUser/audit_waiting.css" type="text/css" />
{/block}
